<template>
  <div>
    <div class="main_content">
      <!-- <el-input
        style="width:200px;"
        clearable
        v-model="searchText"
        placeholder="请输入查询关键字"
        @keydown.enter.native="doSearch()"
      ></el-input>
      <el-button type="primary" @click="doSearch()" class="added">
        <i class="el-icon-search"></i>
        搜索
      </el-button> -->
      <el-row class="tuJian">
        <span>土建专业</span>
      </el-row>
      <!-- <el-table
        :data="tableData"
        border
        style="width: 100%;margin-top:10px;"
        :header-cell-style="tableHeaderStyle"
      >
        <el-table-column prop="name" label="项目名称" align="center"></el-table-column>
        <el-table-column prop="address" label="定义规范" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="140">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleEdit(scope.$switch, scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          small
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="thePageSize"
          layout="total, prev, pager, next, jumper"
          :total="myTotal"
        ></el-pagination>
      </div> -->
      <myTable
        auto='getAllList'
        style='margin-top:15px'
        :height="Height-220"
        min-width='130'
        :myColumn=tableProp
        ahide='index,checkbox,mySplitPage,tooltip,background'
        hide="checkbox"
        slots='操作,250,right'
        select='console'
        hook:created=' myTable.tableData = tableData '
        >
        <template slot-scope='button'>
          <el-upload
            class="uploadfile"
            action=""
            :http-request="uploadPDF"
            :show-file-list="false"
            style="display:inline;margin-left:10px;"
          >
            <el-button type="primary" size="mini" @click="doUpload(button.scope.$index, button.scope.row)">
              <i class="el-icon-folder"></i>
              上 传
            </el-button>
          </el-upload>
          <el-button type="success" size="mini" @click="showConcent(button.scope.$index, button.scope.row)">
            <i class="el-icon-download"></i>
            下 载
          </el-button>
          <el-button type="primary" size="mini" @click="handleEdit(button.scope.$index, button.scope.row)" style="margin-left:0 !important">
            <i class="el-icon-edit"></i>
            编 辑
          </el-button>
        </template>
      </myTable>
    </div>
  </div>
</template>
<script>
import myhttp, {
  isEmpty,
  msgError,
  msgSuccess,
  msgWarning
} from "../../utils/myhttp";
import qs from "qs";
import api from "../../utils/api";
export default {
  data() {
    return {
      loading: "",
      tableHeaderStyle: {
        //表头样式
        "background-color": "rgb(242,242,242)"
      },
      theRow: {}, //当前行数据
      theIndex: 0, //当前下标
      searchText: "", //搜索字段
      myTotal: 1, //分页总条数，默认1
      currentPage: 1, //初始化当前页
      nowPage: 1, //当前页
      thePageSize: 15, //每页条数
      tableData: [],
      tableProp: [
        { label: "帮助字段", prop: "projectNoun" },
        { label: "规范详情", prop: "text" },
        { label: "规范补充", prop: "supplementText"},
      ],
      url:'http://47.104.23.200:8014/yz_file/word/',
    };
  },
  components: {},
  methods: {
    doUpload(index,row){
      this.theRow = row.helpId;
    },
    uploadPDF:async function(param){
      this.openLoading();
      var testmsg = param.file.name.substring(
        param.file.name.lastIndexOf(".") + 1
      );
      if (testmsg === "pdf") {
        let fileName = param.file.name;
        let xlsname = fileName.substring(0, fileName.lastIndexOf("."));
        let fileObject = param.file;
        let id= this.theRow;
        let formData = new FormData();
        formData.append("fileName", fileName=fileName.slice(0,-4));
        formData.append("helpId", id);
        formData.append("file", fileObject);
        // return console.error(param);
        $.file(api.uploadFilePdf,formData,(res,err)=>{
          this.loading2.close();
          if(res.result !== 'success'||err) return $.msgError(res.msg||'error!');
          $.post('upPDF',{
            helpId: id,
            fileName: fileName
          });
          $.msgSuccess(res.msg||'success!');
          this.getAllList();
        });
      } else {
          this.$message.error("上传文件只能是 pdf 格式!");
          this.loading2.close();
          return false;
      };
    },
    showConcent(index,row){
      myhttp.downloadFile( this.url + row.fileName + '.pdf', "");
      /* if(row.helpId === "1"){
        myhttp.downloadFile( this.url + '1.pdf', "");
      } else if(row.helpId === "2"){
        myhttp.downloadFile( this.url + '2.pdf', "");
      } else if(row.helpId === "3"){
        myhttp.downloadFile( this.url + '3.pdf', "");
      } else if(row.helpId === "4"){
        myhttp.downloadFile( this.url + '4.pdf', "");
      } else if(row.helpId === "5"){
        myhttp.downloadFile( this.url + '5.pdf', "");
      } else if(row.helpId === "6"){
        myhttp.downloadFile( this.url + '6.pdf', "");
      } else if(row.helpId === "7"){
        myhttp.downloadFile( this.url + '7.pdf', "");
      } else if(row.helpId === "8"){
        myhttp.downloadFile( this.url + '8.pdf', "");
      } else if(row.helpId === "9"){
        myhttp.downloadFile( this.url + '9.pdf', "");
      } */
    },
    handleEdit(index, row) {
      this.$router.push({
        name:"helpDetails",
        params: {
          help_id: row.helpId,
          texts: row.text,
          project_noun: row.projectNoun,
          modify_person: (row.modifyPerson) || '--',
          modify_time: (row.modifyTime) || '--',
          supplement_text: row.supplementText,
        }
      });
    },
    doSearch() {
      //搜索方法
      this.getAllList();
    },
    openLoading() {
      //loading请求等待
      this.loading2 = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    getAllList: async function(pageNum,pageSize) {
      var res = await $.post('getAllHelp',{
        pageNum, //当前页
        pageSize,//每页显示条数
      });
      // console.log(arguments);
      $return('__',res);
      res = res.items;
    }
  },
  created() {},
  mounted() {}
};
</script>
<style scoped>
  .tuJian{
    /* margin: 20px 0; */
    border:1px solid #d4d4d4;
    padding:15px 0px 15px 20px;
  }
</style>


